//
//  CerterViewController.m
//  HubeiHotel
//
//  Created by LiBenCan on 17/11/20.
//  Copyright © 2017年 张露杰. All rights reserved.
//

#import "CerterViewController.h"

#import <SDCycleScrollView.h>
#import "scrollVCell.h"
#import "HBHChouseTypeView.h"
#import "JiuDianCell.h"
#import "HBHMainIconCell.h"
@interface CerterViewController ()<HWDNavHeadViewDelegate,UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate>

@property (nonatomic, strong) UITableView *table;
@property (nonatomic,strong)SDCycleScrollView *cycleScrollView;//轮播
@property (nonatomic,strong)NSArray *btnArr;
@property (nonatomic,strong)NSArray *titles;//搜索标题

@end

@implementation CerterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _titles = @[@"全部",@"附近",@"智能排序"].mutableCopy;
    NSArray *titleArr = @[@"魅力呈现",@"酒店用品",@"酒店开发"];
    [self initTitleWithTitle:titleArr[_TypeNumber]];
    [self.view addSubview:self.table];
    
}

-(NSArray *)btnArr
{
    if (!_btnArr) {
        if (_TypeNumber == 0) {//魅力呈现
            _btnArr = @[
                        @[@"星级风采",@"starstyle_icon"],
                        @[@"时尚潮流",@"shishang_icon"],
                        @[@"特色餐饮",@"tesefood_icon"],
                        @[@"周末休闲",@"xiuxian_icon"],
                        @[@"人气酒店",@"hot_icon"],
                        @[@"行业新贵",@"new_icon"],
                        @[@"游客首选",@"first_icon"],
                        @[@"疗养胜地",@"shengdi_icon"],
                        @[@"商务之星",@"shangwu_icon"],
                        @[@"天然氧吧",@"yang_icon"],
                        @[@"季节出行",@"jijie_icon"],
                        @[@"健身超市",@"jiansheng_icon"],
                        @[@"奇异探险",@"tanxian_icon"],
                        @[@"特产商店",@"techan_icon"],
                        @[@"特色文化",@"culture_icon02"],
                        @[@"奇艺娱乐",@"yule_iconGr"]
                        ];

        }else if (_TypeNumber == 1)//酒店用品
        {
            _btnArr = @[
                        @[@"餐饮用品",@"cup_icon"],
                        @[@"厨房设备",@"chufang_icon"],
                        @[@"家具门锁",@"jiaju_icon"],
                        @[@"灯饰洁具",@"lamp_icon"],
                        @[@"大堂用品",@"datang_icon"],
                        @[@"客房设备",@"room_icon"],
                        @[@"纺织用品",@"cloth_icon"],
                        @[@"办公用品",@"bangong_icon"],
                        @[@"墙纸窗帘",@"chuanglian_icon"],
                        @[@"清洁机器",@"qingjie_icon"],
                        @[@"银行监控",@"shouying_icon"],
                        @[@"其他杂类",@"other_icon"],
                        ];
  
        }else if (_TypeNumber == 2)//酒店开发
        {
            _btnArr = @[
                        @[@"设计装修",@"chuangxiu_icon"],
                        @[@"交易平台",@"pingtai_icon"],
                        @[@"运营管理",@"guanli_icon"],
                        @[@"中介服务",@"zhongjie_icon"],
                        @[@"专业培训",@"peiXun_icon"],
                        @[@"软件开发",@"soft_icon"],
                        @[@"证件办理",@"zhengjian_icon"],
                        @[@"商标注册",@"zhuce_icon"],
                        @[@"法律咨询",@"law_icon"],
                        @[@"代税代帐",@"diasui_icon"],
                        @[@"出让信息",@"sale_icon"],
                        @[@"求购信息",@"qiugou_icon"],
                        ];
        }
    }
    return _btnArr;
}
-(SDCycleScrollView *)cycleScrollView//轮播
{
    if (!_cycleScrollView) {
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0,0,SCREENW,150*screenW_6) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
        _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        _cycleScrollView.currentPageDotColor = [UIColor whiteColor];
        _cycleScrollView.autoScrollTimeInterval = 4.0f;
        _cycleScrollView.userInteractionEnabled = YES;
        _cycleScrollView.delegate = self;
    }
    return _cycleScrollView;
}

-(UITableView *)table
{
    if (!_table) {
        _table = [[UITableView alloc]initWithFrame:CGRectMake(0,0, SCREENW, SCREENH-64) style:UITableViewStylePlain];
        _table.delegate = self;
        _table.dataSource = self;
        _table.showsHorizontalScrollIndicator = NO;
        _table.showsVerticalScrollIndicator = NO;
        _table.separatorStyle = 0;
        _table.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
        _table.backgroundColor = backColor;
    }
    return _table;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section != 0) {
        return 41*screenW_6;
    }
    return 0.000001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 5*screenW_6;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 2;
    }
    return 5;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            scrollVCell *cell= [tableView dequeueReusableCellWithIdentifier:@"scrollVCell"];
            if (!cell) {
                cell = [[scrollVCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"scrollVCell"];
            }
            [cell loadCellWithData:nil];
            return cell;
        }else{//主按钮Cell
            HBHMainIconCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HBHMainIconCell"];
            if (!cell) {
                cell = [[HBHMainIconCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HBHMainIconCell"];
            }
            if (_TypeNumber == 0) {//魅力呈现
                   [cell loadFangCellWithIcons:self.btnArr];
            }else
            {
                [cell loadTopDownCellWithIcons:self.btnArr];
            }
         
            return cell;
        }
    }else{//求职招聘
        JiuDianCell *cell = [tableView dequeueReusableCellWithIdentifier:@"JiuDianCell"];
        if (!cell) {
            cell = [[JiuDianCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"JiuDianCell"];
        }
        [cell loadCellWithData:@{@"title":@"民宿客栈",@"sub":@"风里雨里公司等你",@"adress":@"洪山区",@"money":@"188",@"discount":@"337"}];
        return cell;
    }
    return nil;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 41*screenW_6)];
        view.backgroundColor = [UIColor whiteColor];
        for (int i = 0; i < _titles.count; i++) {
            HBHChouseTypeView *typeView = [[HBHChouseTypeView alloc]initWithFrame:CGRectMake(i*SCREENW/3, 0, 0, 0) title:_titles[i] complete:^(NSString *title) {
                
            }];
            [view addSubview:typeView];
            if (i < 2) {
                UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(typeView.frame) - .5, 0, 1, 14*screenW_6)];
                lineView.backgroundColor = backColor;
                [view addSubview:lineView];
                lineView.center = CGPointMake(lineView.center.x, view.frame.size.height/2);
            }
        }
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 41*screenW_6 - .5, SCREENW, .5)];
        lineView.backgroundColor = backColor;
        [view addSubview:lineView];
        return view;
    }
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return 150*screenW_6;
        }else{
            return (2.5+82.5*(_btnArr.count/4))*screenW_6;
        }
    }else{
        return 150*screenW_6;
    }
    return 0;
}
@end
